---------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/tomasdomingueziino/Dropbox/Research/jmp/current/data_new/shap
> efiles/raw/Ehrl_AMCgeneration_EE/_Crosswalk_1991_2010_final.log
  log type:  text
 opened on:   8 Apr 2021, 10:38:02

. 
. *** use the last generated data set
. use "_Crosswalk_`y_1'.dta", clear

. 
. *** drop unecessary information:
. keep uf_amc code2010 final_name clu*_final

. 
. 
. *** solve remaining problems
. ** generate auxiliary cluster variable
. gen clu`y_1'_final2=clu`y_1'_final
(27 missing values generated)

. 
. ** last changes (semi-manual)
. // see "_Crosswalk_pre.do" - destiny/origin outside their own UF_amc
. if `startyear'<=1872 {
. sum clu`y_1'_final if code2010==2205706
. local n1 = r(mean)
. sum clu`y_1'_final if final_name=="Granja"
. local n0 = r(mean)
. recode clu`y_1'_final2 (`n1' = `n0')
. }

. 
. if `startyear'<=1911 & `endyear'>=1911 {
. sum clu`y_1'_final if code2010==4204202
. local n1 = r(mean)
. sum clu`y_1'_final if code2010==4209003
. local n2 = r(mean)
. sum clu`y_1'_final if code2010==4213609
. local n3 = r(mean)
. sum clu`y_1'_final if final_name=="Palmas" & uf_amc==15
. local n0 = r(mean)
. recode clu`y_1'_final2 (`n1' `n2' `n3' = `n0')
. 
. sum clu`y_1'_final if code2010==4208104
. local n1 = r(mean)
. sum clu`y_1'_final if code2010==4210100
. local n2 = r(mean)
. sum clu`y_1'_final if final_name=="Rio Negro" & uf_amc==15
. local n0 = r(mean)
. recode clu`y_1'_final2 (`n1' `n2' = `n0')
. 
. sum clu`y_1'_final if code2010==1100205
. local n1 = r(mean)
. sum clu`y_1'_final if final_name=="Humaita" & uf_amc==1
. local n0 = r(mean)
. recode clu`y_1'_final2 (`n1' = `n0')
. }

. 
. // litigo MG/ES
. if `startyear'<=1940 | `endyear'>=1960 {
. sum clu`y_1'_final if code2010==3203304

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
clu2000_fi~l |         1        1666           .       1666       1666
. local n1 = r(mean)
. sum clu`y_1'_final if code2010==3200904

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
clu2000_fi~l |         1        1637           .       1637       1637
. local n2 = r(mean)
. sum clu`y_1'_final if code2010==3104700

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
clu2000_fi~l |         1        3196           .       3196       3196
. local n0 = r(mean)
. recode clu`y_1'_final2 (`n1' `n2' = `n0')
(clu2000_final2: 2 changes made)
. }

. 
. sort uf_amc 

. egen clu_final=group(clu`y_1'_final2)
(27 missing values generated)

. drop clu`y_1'_final2

. 
. 
. ******************************************
. *** generate a new code for the final AMCs
. 
. *** generate common UF_AMCs first
. recode uf_amc (1 20=1) (4 5=4) (6=5) (7=6) (8=7) (9=8) (10=9) ///
>         (11=10) (12 18=11) (13=12) (14=13) (15 16=14) (17=15) (19=16)
(uf_amc: 4891 changes made)

. label define uf_amc_lb 1 "AM/MT/(RO/RR/MS)" 2 "PA/(AP)" 3 "MA" ///
>         4 "PI/CE" 5 "RN" 6 "PB" 7 "PE" 8 "AL" ///
>         9 "SE" 10 "BA" 11 "ES/MG"  12 "RJ" 13 "SP"  14 "PR/SC"  15 "RS" 16 "GO/
> (DF/TO)" 

. label values uf_amc uf_amc_lb

. 
. *** assign a new cluster number, with UF in first 2 digits
. *** the next two digits refer to the alpabethical position of the mun in an AMC
. 
. bysort uf_amc clu_final (code2010): gen help = 1 if _n==1 & clu_final!=.
(1294 missing values generated)

. bysort help uf_amc (code2010): gen amc_n=_n if help==1
(1294 missing values generated)

. // assign to all other members of the AMC
. sort uf_amc clu_final code2010

. replace amc_n=amc_n[_n-1] if amc_n==.
(1294 real changes made)

. 
. gen amc = uf_amc*1000 if clu_final!=.
(27 missing values generated)

. replace amc=amc + amc_n
(5565 real changes made)

. drop amc_n help

. 
. sum amc clu_final

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         amc |      5565    10174.48    4708.103       1001      21008
   clu_final |      5565    2182.636    1294.863          1       4298

. 
. *** save final data
. sort uf_amc clu_final final_name

. order uf_amc final_name clu_final amc

. save "_Crosswalk_final_`startyear'_`endyear'.dta", replace
file _Crosswalk_final_1991_2010.dta saved

. 
. 
. 
. 
end of do-file

. 
end of do-file

. set more off

. export delimited using _Crosswalk_final_1991_2010.csv
file _Crosswalk_final_1991_2010.csv saved

. do "/var/folders/k1/klyrw3_d0yzcp8bqjsc_h_pc0000gn/T//SD41188.000000"

. 
. version 11.2

. clear all

. set mem 300m

. 
. ** step 1: define the path for the working directory where all files (including
>  the original spreadsheet IBGE_1872_2010_original.xml) are located
. ** all results will also be saved into this directory
. cd "/Users/tomasdomingueziino/Dropbox/Research/jmp/current/data_new/shapefiles/
> raw/Ehrl_AMCgeneration_EE"
/Users/tomasdomingueziino/Dropbox/Research/jmp/current/data_new/shapefiles/raw/Eh
> rl_AMCgeneration_EE

. 
. ** step 2: data preperation
. // independent of chosen period
. do "_Crosswalk_pre.do"

. 
. cap log close
